package model;

import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.lym.syappandroid.R;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

/**
 * Created by lym on 2017/6/2.
 */

public class AlarmAdapter extends ArrayAdapter<Alarm> {
    private int resourceId;

    public AlarmAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<Alarm> objects) {
        super(context, resource, objects);
        resourceId = resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        Alarm alarm = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resourceId,parent,false);
        ImageView alarm_unread = (ImageView) view.findViewById(R.id.iv_alarm_unread);
        if(alarm.isA_isread()){
            alarm_unread.setImageResource(R.drawable.alarm_null);
        }else{
            alarm_unread.setImageResource(R.drawable.alarm_unread);
        }
        TextView alarm_name = (TextView) view.findViewById(R.id.tv_alarm_name);
        alarm_name.setText(alarm.getA_name());
        TextView alarm_time = (TextView) view.findViewById(R.id.tv_alarm_time);
        alarm_time.setText(alarm.getA_timeString());

        return view;
    }
}
